home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2406 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.3 KB

  1. Path: ornews.intel.com!news
  2. From: thurman_b_miller@ccm2.hf.intel.com (Thurman Miller)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: When to use "->" vs "." when calling Member functions
  5. Date: Wed, 17 Jan 1996 17:13:12 GMT
  6. Organization: Intel Corporation
  7. Message-ID: <4djapd$j1m@ornews.intel.com>
  8. References: <4dhea1$6v8@ornews.intel.com> <30FC698D.6D216C84@eiffel.com>
  9. NNTP-Posting-Host: thurman-pc.ssd.intel.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. "Guus Leeuw jr." <guusl@eiffel.com> wrote:
  13.  
  14. >Thurman Miller wrote:
  15. >> 
  16. >> I'm confused, so please no harsh remarks :)
  17. >> 
  18. >> If I've got:
  19. >> 
  20. >> class Cfoo
  21. >> {
  22. >>         something * getptr();
  23. >>         somethingelse* m_other;
  24. >> }
  25. >> 
  26. >> something * foo::getptr()
  27. >> {
  28. >>         return m_other;
  29. >> }
  30. >> 
  31. >> Now...if I'm in another class....
  32. >> 
  33. >>         Cfoo foo;
  34. >>         somethingelse* = foo.getptr();
  35. >> 
  36. >> why doesn't the following work?
  37. >> 
  38. >>         somethingelse* = foo->getptr();
  39. >> 
  40. >> I get compile error about no "->" overloaded operator....
  41. >> 
  42. >> Can someone point out the obvious when I use one notation over
  43. >> another?
  44. >> 
  45. >> TIA
  46. >> 
  47. >> Thurman
  48.  
  49. >Okay, here we go.
  50.  
  51. >When you write "foo->getptr()", you're actually writing
  52. >"(*foo).getptr()". And that is where your problem is.
  53.  
  54. >The selector (`xyz->abc') is used as a shorthand notation for
  55. >`(*xyz).abc', and therefor can only be aplied to pointers to objects. As
  56. >in:
  57. >        Cfoo *foo;
  58. >        somethingelse* = foo->getptr();
  59.  
  60. >Hope this explains,
  61. >    Guus Leeuw jr.
  62.  
  63. I would like to thank each of you for responding. Not only did you
  64. clear this up
  65. but you were all so consistent it is almost baffling!
  66.  
  67. My original problem stemmed from using the document/view architecture
  68. and 
  69. statements like the following:
  70.  
  71.         CRfcXferDoc* pDoc = (CRfcXferDoc*)GetDocument();
  72.         pDoc->SetPlant(plantname);
  73.  
  74. After reading your responses, I saw where my mistake was at. My
  75. example (using 
  76. Cfoo) clearly does not match the actual code above that I had been
  77. basing my 
  78. experience on. Each of your responses was so clear that I immediately
  79. recognized
  80. my error. (not to mention getting the same exact answer three times -
  81. I'm sure 
  82. that helped as well! :)
  83.  
  84. I was concentrating so much on the document that I didn't see the
  85. pointer. Oh 
  86. well...Chalk it up to being a newbie.
  87.  
  88.  
  89. Thanks again!
  90.  
  91. Thurman Miller
  92.  
  93.  
  94.